from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
class MyPage(PageNumberPagination):
    page_query_param = 'page' # ?page=1
    page_size_query_param = 'pagesize' # ?pagesize=5
    max_page_size = 20
    page_size = 5 # 默认每页数量

    def get_paginated_response(self, data):
        # data就是一当前页数据
        return Response({
            'count': self.page.paginator.count, # 总数量
            'next': self.get_next_link(),
            'previous':self.get_previous_link(),
            'results':data
        })

